package com.neu;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

/**
 * @author 杜佳辉
 * @version 1.0
 * @date 2024-12-05-15:03
 */
public class MyWatcher implements Watcher {
    @Override
    public void process(WatchedEvent event) {
        //判断事件类型，连接类型
        switch (event.getType()) {
            case None:
                switch (event.getState()) {
                    case SyncConnected:
                        System.out.println("连接成功");
                        break;
                    case Disconnected:
                        System.out.println("断开连接");
                        break;
                    case Expired:
                        System.out.println("连接超时");
                        break;
                    default:
                        System.out.println("其他事件");
                        break;
                }
                break;
            case NodeCreated:
                System.out.println("节点创建");
                break;
            case NodeDeleted:
                System.out.println("节点删除");
                break;
            case NodeDataChanged:
                System.out.println("节点数据变化");
                break;
            case NodeChildrenChanged:
                System.out.println("节点子节点变化");
                break;
            default:
                System.out.println("其他事件");
                break;
        }
    }
}
